home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / cli / getdate.lha / getdate / getdate.c next >
Encoding:
C/C++ Source or Header  |  1999-07-12  |  1.3 KB  |  53 lines

  1. #include <proto/exec.h>
  2. #include <proto/dos.h>
  3. #include <proto/locale.h>
  4. #include <exec/memory.h>
  5. #include <dos/rdargs.h>
  6.  
  7. static __saveds __asm void PrintHookFunc(register __a1 LONG);
  8.  
  9. struct Arguments {LONG PrintTime;};
  10.  
  11. struct DosLibrary *DOSBase;
  12.  
  13. LONG __saveds main(void)
  14. {
  15. UBYTE ProgName[80];
  16. LONG rcode=RETURN_OK;
  17. struct RDArgs *Args;
  18. struct Library *LocaleBase ;
  19. static const struct Hook PrintHook = {{NULL,NULL},(void*)(&PrintHookFunc),NULL,NULL};
  20. static struct Arguments args={0};
  21.  
  22.     if(DOSBase = (struct DosLibrary*)OpenLibrary("dos.library",37))
  23.     {
  24.         GetProgramName(ProgName,sizeof(ProgName));
  25.         if(LocaleBase = OpenLibrary("locale.library",38))
  26.         {
  27.             if(Args = ReadArgs("Time/S",(LONG*)(&args),NULL))
  28.             {
  29.             static struct DateStamp ds;
  30.             struct Locale *loc;
  31.                 loc = OpenLocale(NULL);
  32.                 DateStamp(&ds);
  33.                 FormatDate(loc,args.PrintTime?"%Y%m%d%H%M%S\n":"%Y%m%d\n",&ds,(struct Hook*)&PrintHook);
  34.                 CloseLocale(loc);
  35.                 FreeArgs(Args);
  36.             } else
  37.             {
  38.                 PrintFault(IoErr(),ProgName);
  39.                 rcode = RETURN_WARN;
  40.             }
  41.             CloseLibrary(LocaleBase);
  42.         } else
  43.         {
  44.             Printf("%s: error opening %s V38!\n",ProgName,"locale.library");
  45.             rcode = RETURN_FAIL;
  46.         }
  47.         CloseLibrary((struct Library*)DOSBase);
  48.     } else rcode=RETURN_FAIL;
  49.     return rcode;
  50. }
  51.  
  52. static __saveds __asm void PrintHookFunc(register __a1 LONG c) {UBYTE s[2]; s[0]=c; s[1]='\0'; PutStr(s); }
  53.